<p><strong><a href="http://fluentstatement.codeplex.com">FluentStatement 2.00</a></strong>&nbsp;Codename <em>Spring Cleaning (isn't it Summer!?)</em><br /> <br /> by M. Alberti&nbsp;(xanatos(at)live.it)</p>
<ul>
<li>
<p>What is FluentStatement?</p>
<p>FluentStatement is a fluent library for C# and .NET that lets the user create Lambda Expression(s) through its fluent (2nd and last time this word is used) interface. These Lambda Expressions can contain statements. All the standard statements of C# are  included (<em>{...}</em>, <em>while {...}</em>, <em>do {...} while</em>, <em>for {...}</em>, <em>foreach {...}</em>, <em>if {...}</em>, <em>switch {...}</em>, <em>using {...}</em>, <em>try {...} catch {...} finally {...}</em>, <em>throw</em>, <em>lock {...}</em>), plus a favourite of mine, the <em>trylock {...}</em>, and the quite-famous <em>do {...} until</em> statements. Also present are methods to do assignments in Lambda Expressions.</p>
<p>As a free gift you get some extension <em>Expression</em>s (not in the C# Method Extension sense but in the <em>Extension.NodeType == ExpressionType.Extension</em> and <em>Extension.CanReduce == true</em> sense): <em>while {...}</em>, <em>do {...} while</em>, <em>do {...} until</em>, <em>for {...}</em>, <em>foreach {...}</em>, <em>using {...}</em>, <em>lock {...}</em>, <em>trylock {...}</em> (<em>Two for the Price of One</em>, in fact). For these look at the <em>ExpressionEx</em> class (sorry, no examples nor unit tests.)</p>
</li>
<li>
<p>Why is this library useful?</p>
<p>The C# 4.0 and 4.5 compilers support Lambda Expressions and Lambda Statements. Sadly only the first ones are compilable to Expression Trees and are manipulable at runtime. Lambda Expressions can't contain statements, can't assign values to fields, properties  or local variables (directly through the use of the = operator or indirectly through the use of the ++, --, +=, -= ... operators) and have other limits (empty Lambda Expression can't be built directly, throws statement can't be used, ...) It's now few years  that fluent programming is very very trendy. Fluent interfaces are normally based on the Lambda Expression support of the C# compiler. This library helps building more complex Lambda Expressions that can contain statements, and it's fluent, and it's easily  expandable to include more "verbs."</p>
</li>
<li>
<p>What about a small code sample?</p>
<pre>    var list = new List&lt;int&gt;() { 1, 2, 3, 4, 5 };

    Expression&lt;Func&lt;IEnumerable&lt;int&gt;, int&gt;&gt; sum = 
        enu =&gt; FluentStatement.Start(s =&gt; 
            s.Block(
                new { sum = 0 }, 
                q =&gt; s.ForEach(
                    enu, 
                    ele =&gt; s.Increase(q.sum, ele)
                ).Return(q.sum)
            ).DefaultValue&lt;int&gt;()
        );

    sum = sum.Expand();

    Func&lt;IEnumerable&lt;int&gt;, int&gt; sum2 = sum.Compile();
    var total = sum2(list);</pre>
	
Note that from version 2.0 you could even do something like this (without using the anonymous object):
	
<pre>            s.Block(
                0, 
                q =&gt; s.ForEach(
                    enu, 
                    ele =&gt; s.Increase(q, ele)
                ).Return(q)
            )</pre>	
<p>This code will generate a sum Expression (and a sum2 delegate to use it). It is equivalent to the <em>IEnumerable&lt;int&gt;.Sum()</em> extension method. The <em>DefaultValue&lt;int&gt;()</em> is necessary because all the "verbs" of FluentStatement return a Statement object. Only <em>Value&lt;T&gt;</em> and <em>DefaultValue&lt;T&gt;</em> return T, so they can be used to "close" expressions that must return a value. All the FluentStatement "sentences" start with a</p>
<pre>    () =&gt; FluentStatement.Starts(s =&gt;
</pre>
<p>or, if they have parameters</p>
<pre>    (par1, ...) =&gt; FluentStatement.Starts(s =&gt; 
</pre>
<p>FluentStatement "sentences" that must return a value end with a</p>
<pre>    .Value&lt;T&gt;(something)
</pre>
<p>or a</p>
<pre>    .DefaultValue&lt;T&gt;() 
</pre>
</li>
<li>
<p>Why are there so few operation + assignment "verbs"? Why no <em>Multiply</em>, <em>Divide</em>, <em>Mod</em>, <em>ShiftLeft</em>, <em>ShiftRight</em>, <em>And</em>, <em>Or</em>, <em>Xor</em>, ...?</p>
<p>FluentStatement includes only the most common (operation + assignment) "verbs", <em>Pre</em>/<em>Post</em> <em>Increment</em>/<em>Decrement</em> (++/--), <em>Increase</em> and <em>Decrease</em> (+=/-= .) Other verbs can easily be added by the user.</p>
</li>
<li>
<p>What versions of .NET does it support?</p>
<p>FluentStatement requires .NET 4.0. It has been tested with Mono 2.10.8.</p>
</li>
<li>
<p>What license is FluentStatement released under?</p>
<p>FluentStatement is released under the MIT license. If you need something more liberal (a beerware license?) you can ask me.</p>
</li>
<li>
<p>What is included in the solution?</p>
<p>The solution includes the projects:</p>
<ul>
<li>
<p>FluentStatement, the main library</p>
</li>
<li>
<p>Sample, a small code sample that shows many "verbs"</p>
</li>
<li>
<p>Tests, the unit test that tests all the verbs and show how they can be used.</p>
</li>
</ul>
</li>
<li>
<p>Where does the idea come from?</p>
<p>The base idea (especially on the use of the anonymous objects) comes from a series of articles Mitsu wrote on his <a href="http://blogs.msdn.com/b/mitsu/">blog</a></p>
</li>
<li>
<p>Have you used unit testing?</p>
<p>FluentStatement uses extensively unit testing. It uses <a href="http://xunit.codeplex.com"> xUnit</a> (minimum version 1.9.0) xUnit must be installed in the folder <em>C:\xUnit</em> to use the Tests project. If your installation of xUnit is in a different folder, please modify in the <em>Tests.csproj</em> file the line <em>&lt;XUnitPath&gt;C:\xUnit&lt;/XUnitPath&gt;</em>.</p>
</li>
<li>
<p>Why is your code so obsessively-compulsively tidy?</p>
<p>FluentStatement (and its author) are proud users of <a href="http://stylecop.codeplex.com"> StyleCop</a> (minimum version 4.7). A clean code is a sign of respect for those who will use it. The projects included in the solution will try to use the MSBuild include file for StyleCop if present in the folder <em>$(ProgramFiles)\MSBuild\StyleCop\v4.7</em> folder (where <em>$(ProgramFiles)</em> is normally <em>C:\Program Files</em> or <em>C:\Program Files (x86)</em> .) To install the MSBuild include file you have to check the <em>MSBuild integration</em> checkbox during the installation of StyleCop.</p>
</li>
<li>
<p>Why isn't the code commented?</p>
<p>FluentStatement (and its author) are proud users of StyleCop. Sadly the author is too much lazy to document the code. This is a sign of disrespect for those who will use it, but the author isn't very worried :-) Fortunately for the author, there are settings  in StyleCop to disable the checking of comments.</p>
</li>
<li>
<p>Why is your English so much poor?</p>
<p>FluentStatement has been written by an author who speaks very well Italian, but not so well British English or American English (or any other English idiom.) This is unfortunate, perhaps even tragic :-)</p>
</li>
<li>
<p>Known bugs</p>
<ul>
<li>
<p>Dynamic types aren't supported.</p>
</li>
</ul>
</li>
<li>
<p>Release history:</p>
<ul>
<li>
<p>2012-07-30 Version 2.00 Codename: <em>Spring Cleaning (isn't it Summer!?)</em></p>
<p>Added an option for using <em>Block</em> and <em>ForEach</em> with a single variable, without building first an anonymous object. Fixed a bug with chaining extension "fluent" methods (methods declared in subclasses of the <em>Visitor</em>.)</p>
<p><b>Breaking change:</b> renamed many classes, removing the <em>FluentStatement</em> from their names.</p>
</li>
<li>
<p>2012-07-17 Version 1.20 Codename: <em>Two for One, only at FluentStatement</em></p>
<p>Fixed the <em>ForEach</em> to accept non-<em>IEnumerable&lt;T&gt;</em> types. Added a test for the duck-typing. Added the <em>do {...} until</em> expression. Added extension <em>Expression</em>s for <em>while {...}</em>, <em>do {...} while</em>, <em>do {...} until</em>, <em>for {...}</em>, <em>foreach {...}</em>, <em>using {...}</em>, <em>lock {...}</em>, <em>trylock {...}</em>) usable without the <em>FluentStatement</em> syntax.</p>
</li>
<li>
<p>2012-07-15 Version 1.11 Codename: <em>If it walks like a duck (part 2)</em></p>
<p>Fixed a small bug in the <em>Using</em> statement where <em>ValueType</em>s weren't correctly disposed.</p>
</li>
<li>
<p>2012-07-12 Version 1.10 Codename: <em>If it walks like a duck</em></p>
<p>Fixed the duck-typing of <em>ForEach</em>. Now it should be able to find the currect "visible" methods <em>GetEnumerable()</em> and <em>MoveNext()</em> and property <em>Current</em>.</p>
</li>
<li>
<p>2012-07-09 Version 1.00 Codename: <em>Let's hope it isn't the last</em></p>
<p>First public release.</p>
</li>
</ul>
</li>
</ul>
<p>The README is finished. Now go playing with the library.</p>